﻿/*----------------------------------------------------------------
  //Copyright (C) 2012 赵国伟
  //文件功能描述：省份，城市，区域管理Ajax请求服务端处理程序。
  //创建人：赵国伟
  //生成时间：2012/04/22 17:15:00
//----------------------------------------------------------------*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using Shopping.Common;
using Shopping.BLL;
using Shopping.Model;

public partial class Manage_AS_ProvinceCityAreaCommon : BaseManagePage
{
    private readonly ProvinceCityAreasManage bllArea = new ProvinceCityAreasManage();
    private ReturnValue ret = new ReturnValue();

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            string action = Request.QueryString["Action"] as string;
            switch (action)
            {
                case "SaveProvince":   //保存省份信息； by 赵国伟 2012-04-02
                    SaveProvince();
                    break;
                case "GetProvinceInfo":  //查询一条指定的省份信息；by 赵国伟  2012-04-02
                    GetProvinceInfo();
                    break;
                case "DeleteProvince":  //删除一条指定的省份信息； by 赵国伟  2012-04-02
                    DeleteProvince();
                    break;
                case "SaveCity":  //保存一条城市信息；by 赵国伟  2012-04-02
                    SaveCity();
                    break;
                case "GetCityInfo":  //查询一条指定的城市信息；by 赵国伟  2012-04-02
                    GetCityInfo();
                    break;
                case "DeleteCity":  //删除一条城市信息； by 赵国伟  2012-04-02
                    DeleteCity();
                    break;
                case "GetCitiesByProvinceID":   //查询指定省份下的城市信息；
                    GetCitiesByProvinceID();
                    break;
                case "SaveArea":  //保存一条区域信息； by 赵国伟  2012-04-02
                    SaveArea();
                    break;
                case "GetArea":  //查询一条指定的区域信息；by 赵国伟  2012-04-02
                    GetArea();
                    break;
                case "DeleteArea": //删除一条指定的区域信息；by 赵国伟  2012-04-02
                    DeleteArea();
                    break;
                case "GetAreasByCityID": //查询指定城市下的区域信息；by 赵国伟 2012-04-04
                    GetAreasByCityID();
                    break;
            }
            Response.End();
        }
    }


    #region "保存省份信息；"
    /// <summary>
    /// 保存省份信息；
    /// </summary>
    private void SaveProvince()
    {
        ret = BLLHelper.Save<ProvinceCityAreasManage, Provinces>("SaveProvince");
        Response.Write(ret.ToJsonString());
    }
    #endregion

    #region "查询一条指定的省份信息；"
    /// <summary>
    /// 查询一条指定的省份信息；
    /// </summary>
    private void GetProvinceInfo()
    {
        int provinceId = Utility.G<int>("ProvinceID");
        Provinces data = bllArea.GetProvinceInfo(provinceId);
        if (data != null)
            Response.Write(data.ToJsonString());
    }
    #endregion

    #region "删除一条指定的省份信息；"
    /// <summary>
    /// 删除一条指定的省份信息；
    /// </summary>
    private void DeleteProvince()
    {
        int provinceId = Utility.G<int>("ProvinceID");
        Response.Write(bllArea.DeleteProvince(provinceId).ToJsonString());
    }
    #endregion



    #region "保存一条城市信息；"
    /// <summary>
    /// 保存一条城市信息；
    /// </summary>
    private void SaveCity()
    {
        ret = BLLHelper.Save<ProvinceCityAreasManage, Cities>("SaveCity");
        Response.Write(ret.ToJsonString());
    }
    #endregion

    #region "查询一条指定的城市信息；"
    /// <summary>
    /// 查询一条指定的城市信息；
    /// </summary>
    private void GetCityInfo()
    {
        int cityId = Utility.G<int>("CityID");
        Cities data = bllArea.GetCityInfo(cityId);
        if (data != null)
            Response.Write(data.ToJsonString());
    }
    #endregion

    #region "删除一条城市信息；"
    /// <summary>
    /// 删除一条城市信息；
    /// </summary>
    private void DeleteCity()
    {
        int cityId = Utility.G<int>("CityID");
        Response.Write(bllArea.DeleteCity(cityId).ToJsonString());
    }
    #endregion

    #region "查询指定省份下的城市信息； by 赵国伟 2012-04-04"
    /// <summary>
    /// 查询指定省份下的城市信息；
    /// </summary>
    private void GetCitiesByProvinceID()
    {
        int provinceId = Utility.G<int>("ProvinceID");
        List<IDNameObj> listOfData = bllArea.QueryCities(provinceId);
        if (listOfData != null)
            Response.Write(JSONHelper.ObjectToJson<List<IDNameObj>>(listOfData));
    }
    #endregion


    #region "保存一条区域信息；"
    // <summary>
    /// 保存一条区域信息；
    /// </summary>
    private void SaveArea()
    {
        ret = BLLHelper.Save<ProvinceCityAreasManage, Areas>("SaveArea");
        Response.Write(ret.ToJsonString());
    }
    #endregion

    #region "查询一条指定的区域信息；"
    /// <summary>
    /// 查询一条指定的区域信息；
    /// </summary>
    private void GetArea()
    {
        int areaId = Utility.G<int>("AreaID");
        AreaInfo data = bllArea.GetArea(areaId);
        if (data != null)
            Response.Write(JSONHelper.ObjectToJson<AreaInfo>(data));
    }
    #endregion

    #region "删除一条区域信息；"
    /// <summary>
    /// 删除一条区域信息；
    /// </summary>
    private void DeleteArea()
    {
        int areaId = Utility.G<int>("AreaID");
        Response.Write(bllArea.DeleteArea(areaId).ToJsonString());
    }
    #endregion

    #region "查询指定城市下的区域信息 by 赵国伟 2012-04-04"
    /// <summary>
    /// 查询指定城市下的区域信息
    /// </summary>
    private void GetAreasByCityID()
    {
        int cityId = Utility.G<int>("CityID");
        List<IDNameObj> listOfData = bllArea.QueryArea(cityId);
        if (listOfData != null)
            Response.Write(JSONHelper.ObjectToJson<List<IDNameObj>>(listOfData));
    }
    #endregion



}